package com.gupao.strategyAndTemplate;

import com.gupao.strategyAndTemplate.abstractLogger.LoggerFactory;
import com.gupao.strategyAndTemplate.proxyLogger.ILoggerFactory;
import com.gupao.strategyAndTemplate.proxyLogger.JDKProxyLoggerFactory;

import java.util.Map;

/**
 * @Description: //TODO:日志模版方法
 * @ClassName: LoggerTemplate
 * @Author: msx
 * @CreateDate: 2018/3/24 18:40
 */
public class LoggerTemplate {

    /**
     * 处理日志的方法
     * @return
     */
    public DoResult doLogger(Logger logger,Map<String,String> params,LoggerType loggerType){
        DoResult result = new DoResult();
        //步骤
        //1.根据日志业务参数，封装为待处理的日志参数
        //2.调用日志的处理方法
        //3.持久日志
        if(params!=null&&params.size()>0){

        }
        //采用工厂方法
        LoggerFactory factory = new LoggerFactory();
        if(loggerType.equals(LoggerType.LOGGER_ACTION)){
            factory.userActionLogger(logger);
        }else  if(loggerType.equals(LoggerType.LOGGER_API)){
            factory.userApiLogger(logger);
        }else  if(loggerType.equals(LoggerType.LOGGER_LOGIN)){
            factory.userLoginLogger(logger);
        }
        //采用动态代理的方式
        ILoggerFactory factory1 = (ILoggerFactory)new JDKProxyLoggerFactory().executeLogger(loggerType.getLoggerObj());
        factory1.executeLogger(logger);
        //其他操作，比如持久化
        result.setSuccess(true);
        return result;
    }
}
